<html>
<head>
 
</head>
<body style="text-align=center;font-size:32px;">
<table align="center">
<tr><td><div id="problemNum" style='background-color:#999999;width:800;text-align:center;font-size:32px;'></div></td></tr>
<tr><td><div id="problemContent" style='word-wrap:break-word;background-color:#bbbbbb;width:800;text-align:left;font-size:20px;'></div></td></tr>
<tr><td><div id="result" style='word-wrap:break-word; color:#ffff22;font-size:48;background-color:#8855ff;width:800;text-align:center;'></div></td></tr>
<tr><td><div id="copyleft" style='word-wrap:break-word; color:#ffff22;font-size:18;background-color:#666666;width:800;text-align:right;'></div></td></tr>
<script language="javascript">
    //---------------------------------//
    // Project Euler 
    //
    // Author:thrombin
    //   Date:2015-12-11
    //---------------------------------//  
var p_order=12;//Problem Order
 
var problem='The sequence of triangle numbers is generated by adding the natural numbers. \
So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:\
<br/>1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...\
<br/>Let us list the factors of the first seven triangle numbers:\
<br/> 1: 1\
 <br/>3: 1,3\
 <br/>6: 1,2,3,6\
<br/>10: 1,2,5,10\
<br/>15: 1,3,5,15\
<br/>21: 1,3,7,21\
<br/>28: 1,2,4,7,14,28\
<br/>We can see that 28 is the first triangle number to have over five divisors.\
<br/>What is the value of the first triangle number to have over five hundred divisors?';
 
//solve the problem
//==============编程思路简介================
//  通过递归的方法得到每一个triangle number
//  通过对小于sqrt(N)的每一个数穷举，得到N的因子个数
//=====================================
 
var A=3;
var B=3;
var i=3;
 
 
while(factor_count(B)<500){
    B=A+i;
    A=B;
    i++;    ;
}
function factor_count(n){
    var tmp=Math.sqrt(n);
    var count=1;
    for(var i=2;i<tmp;i++){
        if(n%i==0)count++;
    }
    return (count*2);
}
 
//update browser
document.getElementById("problemNum").innerHTML="Project Euler-Problem "+p_order;
document.getElementById("problemContent").innerHTML=problem;
document.getElementById("result").innerHTML="Answer:"+B;
document.getElementById("copyleft").innerHTML="CopyLeft@Thrombin    2015";
</script>
</body>
</html>